package com.spike.servlet;

import com.spike.model.Dept;
import com.spike.service.DeptService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/deptUpdatePage")
public class DeptUpdatePageServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String id = req.getParameter("id");
        int i = Integer.parseInt(id);
//        根据id查询部门信息
        DeptService deptService = new DeptService();
        try {
            Dept byId = deptService.findById(i);
            req.setAttribute("dept",byId);
            req.getRequestDispatcher("/WEB-INF/jsp/deptUpdate.jsp").forward(req,resp);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
